using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace Stratman.DesktopProcess.DatabaseSynchronizer
{
    /// <summary>
    /// Writes trace information to the console in a slightly more abbreviated format than the
    /// standard ConsoleTraceListener class.
    /// </summary>
    public class BasicConsoleTraceListener : ConsoleTraceListener
    {
        /// <summary>
        /// Writes a formatted trace event message string to the console.
        /// </summary>
        /// <param name="eventCache">
        /// A TraceEventCache object that contains the current process ID, thread ID, and stack 
        /// trace information.
        /// </param>
        /// <param name="source">
        /// A name used to identify the output, typically the name of the application that 
        /// generated the trace event.
        /// </param>
        /// <param name="eventType">
        /// One of the TraceEventType values specifying the type of event that has caused the 
        /// trace.
        /// </param>
        /// <param name="id">
        /// A numeric identifier for the event.
        /// </param>
        /// <param name="format">
        /// A format string that contains zero or more format items, which correspond to objects in
        /// the args array.
        /// </param>
        /// <param name="args">
        /// An object array containing zero or more objects to format.
        /// </param>
        public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
        {
            if (Filter.ShouldTrace(eventCache, source, eventType, id, format, args, null, null))
                WriteLine(String.Format(format, args));
        }

        /// <summary>
        /// Writes a trace event message string to the console.
        /// </summary>
        /// <param name="eventCache">
        /// A TraceEventCache object that contains the current process ID, thread ID, and stack 
        /// trace information.
        /// </param>
        /// <param name="source">
        /// A name used to identify the output, typically the name of the application that 
        /// generated the trace event.
        /// </param>
        /// <param name="eventType">
        /// One of the TraceEventType values specifying the type of event that has caused the 
        /// trace.
        /// </param>
        /// <param name="id">
        /// A numeric identifier for the event.
        /// </param>
        /// <param name="message">
        /// A message to write.
        /// </param>
        public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
        {
            if (Filter.ShouldTrace(eventCache, source, eventType, id, message, null, null, null))
                WriteLine(message);
        }

        /// <summary>
        /// Writes a message to the console without a trailing EOL character.
        /// </summary>
        /// <param name="message">
        /// A message to write.
        /// </param>
        public override void Write(string message)
        {
            Console.Write(message);
        }

        /// <summary>
        /// Writes a message to the console with a trailing EOL character.
        /// </summary>
        /// <param name="message">
        /// A message to write.
        /// </param>
        public override void WriteLine(string message)
        {
            Console.WriteLine(message);
        }
    }
}
